/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlets;

import beans.Examen;
import beans.ListeEtudiantEns;
import beans.ListeExamenEns;
import beans.ListeNoteEns;
import beans.Note;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author elbeigni
 */
public class ListeNotesECEnsServlet extends HttpServlet {
   

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");//définit le type de réponse, ici, on retourne une page HTML
	PrintWriter out = response.getWriter();//on récupère un objet permettant d'écrire dans la future page HTML
	out.println("<h1>Servlet doGet pour les notes ...</h1>");
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        PrintWriter out = response.getWriter(); //on récupère un objet permettant d'écrire dans la future page HTML
        try 
        {
            if ((String) request.getParameter("EC")!=null || (String) request.getParameter("promotion")!=null)
            {
                ListeExamenEns listeExamen = new ListeExamenEns();
                listeExamen.recupererListeExamenEns(Integer.parseInt(request.getParameter("EC")), 3, 2);
                request.setAttribute("listeExamen", listeExamen);

                ListeEtudiantEns listeEtudiant = new ListeEtudiantEns();
                listeEtudiant.recupererListeEtudiantEns(1);
                request.setAttribute("listeEtudiant", listeEtudiant);

                /*ListeNoteEns listeNote = new ListeNoteEns();
                listeNote.recupererListeNoteEns(Integer.parseInt(request.getParameter("EC")), 2, 1);
                for (Note n : listeNote.getListeNoteEns())
                {
                    out.println(n.getUneNote());
                }
                request.setAttribute("listeNote", listeNote);*/
                gotoPage("/affichage_notes.jsp", request, response);

            }
            else
            {
                gotoPage("/gestion_note.jsp", request, response);
            }
                response.setContentType("text/html;charset=UTF-8"); //définit le type de réponse, ici, on retourne une page HTML
                out.println("Servlet consultation des notes des élèves par les enseignants");

        }
        catch (Exception ex) {
            //out.println(ex.getCause().getMessage());
        }
    }

     private void gotoPage(String adress, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(adress);
    dispatcher.forward(request,response);
  }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Servlet pour l'affichage des notes des éléves par EC";
    }// </editor-fold>

}
